<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        li{
            width: 80px;
            height: 30px;
            border: 1px solid palegreen;
        }
        .active{
           background-color: red;
        }
    </style>
</head>
<body>
    <ul>
        <li>111</li>
        <li>222</li>
        <li>333</li>
        <li>222</li>
    </ul>
    <script>
        var liEles=document.querySelectorAll("li")
        Array.from(liEles).forEach(function(item,i){
            item.onclick=function(){
                setTimeout(function(){
                    Array.from(liEles).forEach(function(item,k){
                        if(i==k)
                          {item.className+="active"}
                          else
                          item.removeAttribute("class")
                    })
                  
                },500
                )
            }
        })
    </script>
</body>
</html>